﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

public partial class MasterPage : System.Web.UI.MasterPage
{
    SoLienLacDataContext db = new SoLienLacDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {

            if ((Session["Username"] != "" || Session["Username"] != null) && Session.Contents["TrangThai"].ToString() == "DaDangNhap")
            {
                var c = from p in db.Admins select p;
                foreach (var q in c)
                {

                    if (Session["Username"].ToString() == q.TenDangNhap)
                    {
                        lbt.Visible = true;
                        span.Visible = true;
                        lblDangNhap.Text = Session["Username"].ToString();
                    }
                }
                var c1 = from p in db.CanBoGiaoViens select new { p.MaCanBoGV, p.MatKhau, p.TenCanBo };
                foreach (var a in c1)
                {
                    if (Session["Username"].ToString() == a.MaCanBoGV)
                    {
                        lbt.Visible = true;
                        span.Visible = true;
                        lblDangNhap.Text = Session["TenCanBo"].ToString();
                    }
                }
                var c2 = from p in db.HocSinhs select new { p.MaHS, p.TenHS };
                foreach (var d in c2)
                {
                    if (Session["Username"].ToString() == d.MaHS)
                    {
                        lbt.Visible = true;
                        span.Visible = true;
                        lbtDoiMK.Visible = true;
                        lblDangNhap.Text = "Phụ huynh của em" + "\t" + Session["TenHS"].ToString();
                    }
                }
            }
            else
            {
                //if ((Session["Username"] == null || Session["Username"].ToString() == "") && Session.Contents["TrangThai"].ToString() == "ChuaDangNhap")
                //{
                //    Response.Redirect("TrangChu.aspx?url=" + Request.Url.PathAndQuery);

                //}

            }
        }
        
    }
    protected void btnDangXuat_Click(object sender, EventArgs e)
    {
       
    }
    protected void lkbDangXuat_Click(object sender, EventArgs e)
    {
       
    }
    protected void lbt_Click(object sender, EventArgs e)
    {
        Session["Username"] = null;
        lbt.Visible = false;
        span.Visible = false;
        Response.Redirect("TrangChu.aspx");
        Session.Abandon();
    }
    protected void lblDangNhap_Click(object sender, EventArgs e)
    {
        string tendn=Session["Username"].ToString();
        var c=from p in db.Admins where p.TenDangNhap==tendn select p.TenDangNhap;
        var c1=from p in db.CanBoGiaoViens where p.MaCanBoGV==tendn select p.MaCanBoGV;
        var c2 = from p in db.HocSinhs where p.MaHS == tendn select p.MaHS;
        if (c.Count() != 0)
        {
            Response.Redirect("~/QuanTri/Default.aspx");
        }
        if (c1.Count() != 0)
        {
            Response.Redirect("~/giaovien/DefaultGV.aspx");
        }
        if (c2.Count() != 0)
        {
            Response.Redirect("TrangThongTinChiTietDiem.aspx?MaHS="+c2.First().ToString());
        }
    }
    protected void lbtDoiMK_Click(object sender, EventArgs e)
    {
        Response.Redirect("TrangThayDoiTK.aspx");
    }
}
